/obj/machinery/vehicle
	name = "Old Truck"
	desc = "This truck is old and dusty, and you can't think of a corporation that has that color or logo. Hell, it doesn't even seem like it'd go anywhere."
	icon = 'vehicles.dmi'
	icon_state = "oldtruck"
	density = 1
	flags = FPRINT
	anchored = 1.0
	var/can_rotate = 1
	var/one_person_only = 0
	var/cargo = list()
	use_power = 0

/obj/machinery/vehicle/captaintruck
	name = "Captain's Truck"
	desc = "A fancy blue truck with obviously good upkeep."
	icon_state = "captaintruck"

/obj/machinery/vehicle/sectruck
	name = "Security Truck"
	desc = "A fast moving truck, for emergency response."
	icon_state = "sectruck"

/obj/machinery/vehicle/miningtruck
	name = "Mining Truck"
	desc = "A rather slow truck, obviously equipped for workers."
	icon_state = "miningtruck"

/obj/machinery/vehicle/medtruck
	name = "Medical Truck"
	desc = "A white truck with sirens! Probably useful for moving people about."
	icon_state = "medtruck"

/obj/machinery/vehicle/syntruck
	name = "Suspicious Truck"
	desc = "A black truck with red windows. Heavily armored."
	icon_state = "syntruck"

/obj/machinery/vehicle/ex_act(severity)
	switch (severity)
		if (1.0)
			for(var/atom/movable/A as mob|obj in src)
				A.loc = src.loc
				ex_act(severity)
			//SN src = null
			del(src)
		if(2.0)
			if (prob(50))
				for(var/atom/movable/A as mob|obj in src)
					A.loc = src.loc
					ex_act(severity)
				//SN src = null
				del(src)

/obj/machinery/vehicle/blob_act()
	for(var/atom/movable/A as mob|obj in src)
		A.loc = src.loc
	del(src)

/obj/machinery/vehicle/Bump(var/atom/A)
	//world << "[src] bumped into [A]"
	return

/obj/machinery/vehicle/relaymove(mob/user, direction)
	if (!user.canmove) return
	//writing my own movement because step is broken.
	switch(direction)
		if(NORTH)
			src.y++
			src.dir = 1
		if(SOUTH)
			src.y--
			src.dir = 2
		if(EAST)
			src.x++
			src.dir = 4
		if(WEST)
			src.x--
			src.dir = 8
		if(NORTHEAST)
			src.y++
			src.x++
		if(NORTHWEST)
			src.y++
			src.x--
		if(SOUTHEAST)
			src.y--
			src.x++
		if(SOUTHWEST)
			src.y--
			src.x--

/obj/machinery/vehicle/verb/eject()
	set name = "Eject"
	set category = "Truck"
	set src = usr.loc

	if (usr.stat)
		return

	var/mob/M = usr
	M.loc = src.loc
	if (M.client)
		M.client.eye = M.client.mob
		M.client.perspective = MOB_PERSPECTIVE
	step(M, turn(src.dir, 180))
	return

/obj/machinery/vehicle/verb/board()
	set name = "Enter"
	set category = "Object"
	set src in oview(1)

	if (usr.stat)
		return

	if (src.one_person_only && locate(/mob, src))
		usr << "\red There is no more room! You can only fit one person."
		return

	var/mob/M = usr
	if (M.client)
		M.client.perspective = EYE_PERSPECTIVE
		M.client.eye = src

	M.loc = src

/obj/machinery/vehicle/verb/unload(var/atom/movable/A in src)
	set name = "Unload Cargo"
	set desc = "Unloads everything from this truck."
	set category = "Object"
	set src in oview(1)

	if (usr.stat)
		return

	if (istype(A, /atom/movable))
		A.loc = src.loc
		for(var/mob/O in view(src, null))
			if ((O.client && !(O.blinded)))
				O << text("\blue <B> [] unloads [] from []!</B>", usr, A, src)
				src.cargo -= A
				A.loc = src.loc

		if (ismob(A))
			var/mob/M = A
			if (M.client)
				M.client.perspective = MOB_PERSPECTIVE
				M.client.eye = M

/obj/machinery/vehicle/verb/load()
	set name = "Load Cargo"
	set desc = "Load something or someone that you are pulling into the truck."
	set category = "Object"
	set src in oview(1)

	if (usr.stat)
		return

	if (((istype(usr, /mob/living)) && (!(ticker) || (ticker && ticker.mode != "monkey"))))
		var/mob/living/H = usr

		if ((H.pulling && !(H.pulling.anchored)))
			if (src.one_person_only && !(istype(H.pulling, /obj)))
				usr << "You may only place items in."
			else
				H.pulling.loc = src
				if (ismob(H.pulling))
					var/mob/M = H.pulling
					if (M.client)
						M.client.perspective = EYE_PERSPECTIVE
						M.client.eye = src

				for(var/mob/O in viewers(src, null))
					if ((O.client && !( O.blinded )))
						O << text("\blue <B> [] loads [] into []!</B>", H, H.pulling, src)
						H.pulling.loc = src
						src.cargo += H.pulling

				H.stop_pulling()